package com.jizhiguo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.CycleInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Scroller;

public class MyScroler extends Activity {
	/** Called when the activity is first created. */
	LinearLayout lay1, lay2, lay;
	private Scroller mScroller;
	private boolean s1, s2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		findViewById(R.id.linearLayout1).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						AnimationSet animationSet = new AnimationSet(true);
						RotateAnimation rotateAnimation = new RotateAnimation(
								0, 270, Animation.RELATIVE_TO_SELF, 0.5f,
								Animation.RELATIVE_TO_SELF, 0.2f);
						rotateAnimation.setDuration(2000);
						animationSet.addAnimation(rotateAnimation);
						v.startAnimation(animationSet);
					}
				});

		ImageView imageView = (ImageView) findViewById(R.id.imageView1);

		imageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				AnimationSet animationSet = new AnimationSet(true);
				RotateAnimation rotateAnimation = new RotateAnimation(0, 270,
						Animation.RELATIVE_TO_SELF, 0.5f,
						Animation.RELATIVE_TO_SELF, 0.5f);
				rotateAnimation.setDuration(1000);
				rotateAnimation.setInterpolator(new CycleInterpolator(1000));
				rotateAnimation.setRepeatCount(10);
				rotateAnimation.setRepeatMode(Animation.REVERSE);
				animationSet.addAnimation(rotateAnimation);
				v.startAnimation(animationSet);
			}
		});

		// mScroller = new Scroller(this, new Interpolator() {
		//
		// @Override
		// public float getInterpolation(float arg0) {
		// // TODO Auto-generated method stub
		// return 0;
		// }
		// });
		//
		// lay1 = new LinearLayout(this) {
		// @Override
		// public void computeScroll() {
		// if (mScroller.computeScrollOffset()) {
		// scrollTo(mScroller.getCurrX(), 0);
		// postInvalidate();
		// }
		// }
		// };
		// lay2 = new LinearLayout(this) {
		// @Override
		// public void computeScroll() {
		// if (mScroller.computeScrollOffset()) {
		// // mScrollX = mScroller.getCurrX();
		// scrollTo(mScroller.getCurrX(), 0);
		// postInvalidate();
		// }
		// }
		// };
		// lay1.setBackgroundColor(this.getResources().getColor(
		// android.R.color.darker_gray));
		// lay2.setBackgroundColor(this.getResources().getColor(
		// android.R.color.white));
		// lay = new LinearLayout(this);
		// lay.setOrientation(LinearLayout.VERTICAL);
		// LinearLayout.LayoutParams p0 = new LinearLayout.LayoutParams(
		// LinearLayout.LayoutParams.FILL_PARENT,
		// LinearLayout.LayoutParams.FILL_PARENT);
		// this.setContentView(lay, p0);
		//
		// LinearLayout.LayoutParams p1 = new LinearLayout.LayoutParams(
		// LinearLayout.LayoutParams.FILL_PARENT,
		// LinearLayout.LayoutParams.FILL_PARENT);
		// p1.weight = 1;
		// lay.addView(lay1, p1);
		// LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams(
		// LinearLayout.LayoutParams.FILL_PARENT,
		// LinearLayout.LayoutParams.FILL_PARENT);
		// p2.weight = 1;
		// lay.addView(lay2, p2);
		// Button tx = new Button(this);
		// Button tx2 = new Button(this);
		// tx.setText("Button1");
		// tx2.setText("Button2");
		// tx.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// if (!s1) {
		// mScroller.startScroll(0, 0, 50, 10, 100);
		// s1 = true;
		// } else {
		// mScroller.startScroll(0, 0, -50, -10, 100);
		// s1 = false;
		// }
		// }
		//
		// });
		// tx2.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// if (!s2) {
		// mScroller.startScroll(0, 0, 50, 20, 100);
		// s2 = true;
		// } else {
		// mScroller.startScroll(20, 20, -50, -20, 100);
		// s2 = false;
		// }
		// }
		// });
		// lay1.addView(tx);
		// lay2.addView(tx2);
	}
}